<?php

/**
 * 报修派单
 * User: hjc19850430@gmail.com
 * Date: 2016/3/10
 * Time: 22:20
 * FileName: RepairMsgtpl.class.php
 * ProjectName: greencampus
 */
class MeetingMsgtpl extends BaseMsgtpl
{
	public function msgToSubscriber($accountId,$basicInfo) { //给会议室预约者发消息
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id' => $basicInfo['pub_user_id']), 'openid,subscribe');
		$url = C('site_url')."/Meeting/MeetingPersonal/meetingDetail/account_id/".$accountId."/basic_id/".$basicInfo['basic_id']."/check/1/type/3";
		//$url = C('site_url')."/meeting/meeting/ucenter/account_id/".$accountId;;
		if($wechatUserInfo['subscribe']) {
			$template_id = 'LavcPhO0bQ4U9kG1EszsQih7bEVC9146-hufgjNPg1A';
			if($basicInfo['pass'] == 1 && $basicInfo['multilevel'] == 2) { //审核通过(不需要多级审核)
				if($basicInfo['type'] == 1) {
					$array = array(
							'first' => array("value" => '会议室预约通过','color' => '#173177'),
							'keyword1' => array("value" => '会议室预约'),
							'keyword2' => array("value" => '审核通过'),
							'keyword3' => array("value" => date('Y-m-d H:i:s',time()) ),
							'remark' => array("value" => "谢谢你的支持~","color" => "#173177"),
					);
				} elseif($basicInfo['type'] == 2) {
					$array = array(
							'first' => array("value" => '户外场所预约通过','color' => '#173177'),
							'keyword1' => array("value" => '户外场所预约'),
							'keyword2' => array("value" => '审核通过'),
							'keyword3' => array("value" => date('Y-m-d H:i:s',time()) ),
							'remark' => array("value" => "谢谢你的支持~","color" => "#173177"),
					);
				}

			} elseif($basicInfo['pass'] == 1 && $basicInfo['multilevel'] == 1) { //审核通过(需要多级审核)
				if($basicInfo['multilevel_pass'] == 1) { //多级审核通过
					if($basicInfo['type'] == 1) {
						$array = array(
								'first' => array("value" => '会议室预约通过','color' => '#173177'),
								'keyword1' => array("value" => '会议室预约'),
								'keyword2' => array("value" => '审核通过'),
								'keyword3' => array("value" => date('Y-m-d H:i:s',time()) ),
								'remark' => array("value" => "谢谢你的支持~","color" => "#173177"),
						);
					} elseif($basicInfo['type'] == 2) {
						$array = array(
								'first' => array("value" => '户外场所预约通过','color' => '#173177'),
								'keyword1' => array("value" => '户外场所预约'),
								'keyword2' => array("value" => '审核通过'),
								'keyword3' => array("value" => date('Y-m-d H:i:s',time()) ),
								'remark' => array("value" => "谢谢你的支持~","color" => "#173177"),
						);
					}

				} elseif($basicInfo['multilevel_pass'] == 2) { //多级审核不通过
					if($basicInfo['type'] == 1) {
						$array = array(
								'first' => array("value" => '会议室预约不通过','color' => '#173177'),
								'keyword1' => array("value" => '会议室预约'),
								'keyword2' => array("value" => '审核不通过'),
								'keyword3' => array("value" => date('Y-m-d H:i:s',time()) ),
								'remark' => array("value" => "谢谢你的支持~","color" => "#173177"),
						);
					} elseif($basicInfo['type'] == 2) {
						$array = array(
								'first' => array("value" => '户外场所预约不通过','color' => '#173177'),
								'keyword1' => array("value" => '户外场所预约'),
								'keyword2' => array("value" => '审核不通过'),
								'keyword3' => array("value" => date('Y-m-d H:i:s',time()) ),
								'remark' => array("value" => "谢谢你的支持~","color" => "#173177"),
						);
					}


				}
			} elseif($basicInfo['pass'] == 2) { //初级审核不通过

				if($basicInfo['type'] == 1) {
					$array = array(
							'first' => array("value" => '会议室预约不通过','color' => '#173177'),
							'keyword1' => array("value" => '会议室预约'),
							'keyword2' => array("value" => '审核不通过'),
							'keyword3' => array("value" => date('Y-m-d H:i:s',time()) ),
							'remark' => array("value" => "谢谢你的支持~","color" => "#173177"),
					);
				} elseif($basicInfo['type'] == 2) {
					$array = array(
							'first' => array("value" => '户外场所预约不通过','color' => '#173177'),
							'keyword1' => array("value" => '户外场所预约'),
							'keyword2' => array("value" => '审核不通过'),
							'keyword3' => array("value" => date('Y-m-d H:i:s',time()) ),
							'remark' => array("value" => "谢谢你的支持~","color" => "#173177"),
					);
				}
			}

			$res = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);
			return $res;
		}
	}

	/**
	 * 推送消息给会议室初审人员
	 * @param $accountId
	 * @param $userId
	 * @param $basicInfo
	 * @return array|bool|mixed
	 */
	public function msgToChecker($accountId,$userId,$basicInfo) {
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$userId), 'openid,subscribe');
		$url = C('site_url')."/meeting/meetingAppoint/appointDetails/basic_id/{$basicInfo['basic_id']}/account_id/".$accountId."/audited/1";

		$roomInfo = M('MeetingRoom')->where(array('meeting_room_id' => $basicInfo['meeting_room_id']))->find();
		if($wechatUserInfo['subscribe']) {
			$template_id = '6gwrclABSEmF66kUE1ycZ6FcPiDk-FeAwGXBbBxCilU';

			if($basicInfo['type'] == 1) {
				$array = array(
						'first' => array("value" => '您有一个新的待审核会议，请及时处理！','color' => '#173177'),
						'keyword1' => array("value" => $basicInfo['title'].','.$roomInfo['room_name']),
						'keyword2' => array("value" => date('Y-m-d H:i',$basicInfo['start_time']).'至'.date('Y-m-d H:i',$basicInfo['end_time'])),
						'remark' => array("value" => "请尽快审核~","color" => "#173177"),
				);
			} elseif($basicInfo['type'] == 2) {
				$array = array(
						'first' => array("value" => '您有一个新的待审核户外场所，请及时处理！','color' => '#173177'),
						'keyword1' => array("value" => $basicInfo['title'].','.$roomInfo['room_name']),
						'keyword2' => array("value" => date('Y-m-d H:i',$basicInfo['start_time']).'至'.date('Y-m-d H:i',$basicInfo['end_time'])),
						'remark' => array("value" => "请尽快审核~","color" => "#173177"),
				);
			}


			$res = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);
			return $res;
		}
	}


	/**
	 * 推送消息给会议室复审人员
	 * @param $accountId
	 * @param $userId
	 * @param $basicInfo
	 * @return array|bool|mixed
	 */
	public function msgToReview($accountId,$userId,$basicInfo) {
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$userId), 'openid,subscribe');
//		$url = C('site_url')."/meeting/meetingAppoint/unaudited/account_id/".$accountId;
		$url = C('site_url')."/meeting/meetingAppoint/appointDetails/basic_id/{$basicInfo['basic_id']}/account_id/".$accountId."/audited/1";
		if($wechatUserInfo['subscribe']) {
			$template_id = '6gwrclABSEmF66kUE1ycZ6FcPiDk-FeAwGXBbBxCilU';
			if($basicInfo['type'] == 1) {
				$array = array(
						'first' => array("value" => '您有一个新的待审核会议，请及时处理！','color' => '#173177'),
						'keyword1' => array("value" => $basicInfo['title'].','.$basicInfo['room_name']),
						'keyword2' => array("value" => date('Y-m-d H:i',$basicInfo['start_time']).'至'.date('Y-m-d H:i',$basicInfo['end_time'])),
						'remark' => array("value" => "请尽快审核~","color" => "#173177"),
				);
			} elseif($basicInfo['type'] == 2) {
				$array = array(
						'first' => array("value" => '您有一个新的待审核户外场所，请及时处理！','color' => '#173177'),
						'keyword1' => array("value" => $basicInfo['title'].','.$basicInfo['room_name']),
						'keyword2' => array("value" => date('Y-m-d H:i',$basicInfo['start_time']).'至'.date('Y-m-d H:i',$basicInfo['end_time'])),
						'remark' => array("value" => "请尽快审核~","color" => "#173177"),
				);
			}

			$res = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);
			return $res;
		}
	}


	public function msgToInviter($accountId,$basicInfo) { //给会议参加者推消息

		$invite = M('MeetingRegistration')->where(array('basic_id' => $basicInfo['basic_id']))->select();
		if($invite) {
			foreach($invite as $key => $value) {
				$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$value['user_id']), 'openid,subscribe');
				$address = D('MeetingRoom')->getFieldByMeetingRoomId($basicInfo['meeting_room_id'],'address');
				$url = C('site_url')."/meeting/meetingPersonal/meetingDetail/basic_id/".$basicInfo['basic_id'].'/account_id/'.$accountId.'/is_leave/0';
				if($wechatUserInfo['subscribe']) {
					$template_id = 'kv1ONmTT_tdTBwpFUHR2iWs31imwm1gA992k2s9VVvg';
					$array = array(
							'first' => array("value" => '您好，你有一条新的会议邀请！','color' => '#173177'),
							'keyword1' => array("value" => $basicInfo['title']),
							'keyword2' => array("value" => date('Ymd H:i:s',$basicInfo['start_time'])."-".date('Ymd H:i:s',$basicInfo['end_time']) ),
							'keyword3' => array("value" => $address),
							'remark' => array("value" => "请及时确认参会，点此查看详情。","color" => "#173177"),
					);
					$res = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);
					if($res === false) { return false; }
				}
			}
		}
		return $res;
	}


	/**
	 * 获得微信模板
	 * @param $accountId
	 * @return mixed
	 */
	public function getWxTemplate($accountId) {
		if($accountId) {
			switch($accountId) {
				case 2:
					$template_id = 'ervBp_BlUtHqKsaIw0qjmFz2KXy9J1tWCF5TIhW042Q';break;
				case 4:
					$template_id = 'k203JXlZ8F8SCYUIR3uH_HBL8Uq2aAMbAIv2N1r46ec';break;
				case 5:
					$template_id = 'p_P3GalanUy8syyholudeTR3OB5hzEuEAz-w12D_lbQ';break;
				case 6:
					$template_id = 'DAxDdnfAhywT-lfRTsaSGOQwd96g5RQnXMTigQknWCA';break;
				case 10:
					$template_id = 'A4NBwXw1VQmYDOBzCImVstEnwLG2tvbkztK8vbJkc-I';break;
				case 28:
					$template_id = 'Rf7JatKFZNlX-Fji4e2AmRwCvffF8bCsUxdnsHCHAZs';break;
			}
			return $template_id;
		}
		return false;
	}

}